<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>消息</title>
    <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport"/>
    <meta content="yes" name="apple-mobile-web-app-capable"/>
    <meta content="black" name="apple-mobile-web-app-status-bar-style"/>
    <meta content="telephone=no" name="format-detection"/>
    <link href="/css/style.css" rel="stylesheet" type="text/css"/>
    <link rel="stylesheet" href="/css/userTravels.css"/>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <script type="text/javascript" src="/js/jquery/jquery.min.js"></script>
    <script type="text/javascript" src="/js/tab.js"></script>
    <script type="text/javascript" src="/js/slider.js"></script>
    <script type="text/javascript" src="/js/plugins/form/jquery.form.js"></script>
    <script type="text/javascript" src="/js/plugins/jrender/jrender.min.js"></script>
    <script type="text/javascript" src="/js/common.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css">
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script>
        $(function () {
            var user = JSON.parse(sessionStorage.getItem('user'));
            var params = getParams();

            var currentPage;
            //发送请求更改消息的状态
            $.ajax({
                url:"/messages/reads",
                data:{
                    currentPage: currentPage,
                    state: 0,
                    type: params.type
                },
                type:"PUT"
            });
            var currentInput = $("#currentPage");
            var Pages = 1;
            var travelArr=[];
            function query() {
                currentPage = currentInput.val();
                //查询未读的消息

                $.get("/messages/"+user.id+"/unRead",
                    {currentPage:currentPage,state:0,type:params.type},
                    function (data) {
                        console.log(data);
                        $.merge(travelArr, data.list);
                        if(data.pages == 0){
                            $(".messageSingle").html("暂无系统通知!")
                        }else {
                            $(".aui-flex-box").html("查看详情");
                            $(".aui-scrollView").renderValues({list:travelArr},{
                                getHref:function (item,value) {
                                    $(item).attr('href', $(item).data('href') + value);
                                }
                            });
                        }
                        Pages = data.pages;
                    });
                currentInput.val(parseInt(currentPage)+1);

            }

            query();


            $(window).scroll(function () {
                if($(document).scrollTop()+ $(window).height()>= $(document).height()){
                    if(currentInput.val()<=Pages){
                        query();
                    }else{
                        $(document).dialog({
                            type:"notice",
                            infoText:"亲,已经到底啦",
                            autoClose:1000
                        })
                    }

                }

            });

        });
    </script>

</head>
<body>
<input id="currentPage" name="currentPage" value="1" type="hidden">
<div class="search-head">
    <div class="row nav-search">
        <div class="col">
            <a href="javascript:history.go(-1);" >
                <span><i class="fa fa-chevron-left" style="position: relative;top: 10px;"></i></span>
            </a>
        </div>
        <div class="col">
            <span style="position: relative;top: -10px;font-size: 20px">系统通知</span>
        </div>
        <div class="col"></div>
    </div>
</div>
<section class="aui-scrollView">
    <div class="container">
        <hr>
        <div class="messageSingle">
            <div render-loop="list">
                <div class="row info" style="margin:30px;">
                    <a data-href="/travelContent.html?id=" render-key="list.travel.id" render-fun="getHref">
                        <div class="aui-layNews-time" render-html="list.sendTime" style="font-size: 15px"></div>
                       <!-- <div class="aui-flex-logo">
                            <img render-src="list.sender.headImgUrl" style="width: 50px">
                        </div>-->
                        <div class="aui-layNews-text">
                            <div class="aui-layNews-info b-line">
                                <p render-html="list.content" style="font-size: 15px"></p>
                            </div>
                            <div class="aui-flex">
                                <div class="aui-flex-box"></div>
                                <div class="aui-layNews-arrow"></div>
                            </div>
                        </div>

                    </a>

                </div>

            </div>
        </div>
    </div>
</section>
</body>
</html>